package com.stb.server.mail;

import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSenderImpl implements MailSender {

	private static final Logger logger = Logger.getLogger(MailSenderImpl.class.getName());

	@Override
	public void send(String email, String subject, String body) {
		Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("simon_berry2003@yahoo.com", "Admin"));
            msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email));
            msg.setSubject(subject);
            msg.setText(body);
            logger.info("Sending email to " + email);
            Transport.send(msg);
            logger.info("Sent email to " + email);
        } catch (Exception e) {
        	logger.log(Level.WARNING, "Failed to send email", e);
		}		
	}
}
